package krow.dev.gunpobus.view.adapter;

import java.util.ArrayList;
import java.util.List;

import krow.dev.gunpobus.model.NodeItem;
import krow.dev.gunpobus.util.ItemViewFactory;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class NodeListAdapter extends BaseAdapter{

	private LayoutInflater mLayoutInflater;

	private List<NodeItem> mNodeItemList;
	
	private int mRouteType;
	
	public NodeListAdapter(Context context) {
		
		mLayoutInflater = LayoutInflater.from(context);
		
		mNodeItemList = new ArrayList<NodeItem>();
	}
	
	public void setNodeItemList(List<NodeItem> nodeItemList){
		
		mNodeItemList.clear();
		mNodeItemList.addAll(nodeItemList);
	}
	
	public void clear(){
		
		mNodeItemList.clear();
	}
	
	public void setRouteType(int routeType){
		
		mRouteType = routeType;
	}
	
	@Override
	public int getCount() {
		
		return mNodeItemList.size();
	}

	@Override
	public Object getItem(int position) {

		return mNodeItemList.get(position);
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		NodeItem nodeItem = mNodeItemList.get(position);
		
		View view = ItemViewFactory.createNodeView(
				mLayoutInflater,
				nodeItem.getName(),
				nodeItem.hasBus(),
				mRouteType,
				nodeItem.getNodeType(),
				nodeItem);
		
		return view;
	}
}
